{{ template "header" . }}
{{ template "navlist" . }}

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <div class="layadmin-header">
        <div class="layui-card layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
            <a lay-href="">主页</a><span lay-separator="">/</span>
            <a><cite>根据数据库生成代码-控制台</cite></a>
        </div>
    </div>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-header">
                控制台-生成进度
            </div>
            <div class="layui-card-body">
                <input id="input" type="text" style="display: none" />

                <!-- when clicked then an iris websocket event will be sent to the server, at this example we registered the 'chat' -->
                <button onclick="send()" style="display: none" >Send</button>

                <!-- the messages will be shown here -->
                <pre id="output"></pre>
            </div>
        </div>
    </div>
</div>
<!-- /.content-wrapper -->
{{ template "footer" . }}

<script type="text/javascript">
    var scheme = document.location.protocol == "https:" ? "wss" : "ws";
    var port = document.location.port ? (":" + document.location.port) : "";
    // see app.Get("/echo", ws.Handler()) on main.go
    var wsURL = scheme + "://" + document.location.hostname + port+"/echo";

    var input = document.getElementById("input");
    var output = document.getElementById("output");

    // Ws comes from the auto-served '/iris-ws.js'
    var socket = new Ws(wsURL);
    socket.OnConnect(function (data) {
        output.innerHTML += "Status: Connected\n";
        console.log(data)
    });

    socket.OnDisconnect(function () {
        output.innerHTML += "Status: Disconnected\n";
    });

    // read events from the server
    socket.On("console", function (msg) {
        addMessage(msg);
    });

    function send() {
        addMessage("Me: " + input.value); // write ourselves
        socket.Emit("console", input.value);// send chat event data to the websocket server
        input.value = ""; // clear the input
    }

    function addMessage(msg) {
        output.innerHTML += msg + "\n";
    }
</script>
